var prefix = ctx + "manage/versionUpdate";
var prefixConfiguration = ctx + "manage/configuration";
var prefixWithdrawalConfig = ctx + "manage/withdrawalConfig";

$(function () {
    var columns = [{
        checkbox: true
    },
        {
            field: 'id',
            title: '主键'
        },
        {
            field: 'vuChannelPackageName',
            title: '渠道名'
        },
        {
            field: 'vuChannelPackage',
            title: '渠道ID'
        },
        {
            field: 'vuVersionCode',
            title: '版本号'
        },
        {
            field: 'vuVersionName',
            title: '版本名'
        },
        // {
        //     field: 'vuUrl',
        //     title: '下载地址'
        // },
        // {
        //     field: 'vuContent',
        //     title: '跟新内容'
        // },
        // {
        //     field: 'vuStatus',
        //     title: '版本控制'
        // },
        // {
        //     field: 'createTime',
        //     title: '时间'
        // },
        {
            align: 'center',
            title: 'APP配置',
            formatter: function (value, row, index) {
                var actions = [];
                actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryConfiguration(\'' + row.vuChannelPackage + '\')"><i>详细</i></a> ');
                return actions.join('');
            }
        },
        {
            align: 'center',
            title: '提现配置',
            formatter: function (value, row, index) {
                var actions = [];
                actions.push('<a class="btn btn-primary btn-sm" href="#" title="编辑" mce_href="#" onclick="queryWithdrawalConfig(\'' + row.vuChannelPackage + '\')"><i>详细</i></a> ');
                return actions.join('');
            }
        },
        {
            title: '操作',
            align: 'center',
            formatter: function (value, row, index) {
                var actions = [];
                actions.push('<a class="btn btn-primary btn-sm ' + editFlag + '" href="#" title="编辑" mce_href="#" onclick="edit(\'' + row.id + '\')"><i class="fa fa-edit"></i></a> ');
                actions.push('<a class="btn btn-warning btn-sm ' + removeFlag + '" href="#" title="删除" onclick="remove(\'' + row.id + '\')"><i class="fa fa-remove"></i></a>');
                return actions.join('');
            }
        }];
    var url = prefix + "/list";
    $.initTable(columns, url);
});

/*版本更新-新增*/
function add() {
    var url = prefix + '/add';
    layer_showAuto("新增版本更新", url);
}

function queryConfiguration(id){
    var url = prefixConfiguration + "/" + id;
    layer_showAuto("APP配置", url);
}
function queryWithdrawalConfig(id){
    var url = prefixWithdrawalConfig + "/" + id;
    layer_showAuto("APP配置", url);
}

/*版本更新-修改*/
function edit(id) {
    var url = prefix + '/edit/' + id;
    layer_showAuto("修改版本更新", url);
}

// 单条删除
function remove(id) {
    $.modalConfirm("确定要删除选中版本更新吗？", function () {
        _ajax(prefix + "/remove/" + id, "", "post");
    })
}

// 批量删除
function batchRemove() {
    var rows = $.getSelections("id");
    if (rows.length == 0) {
        $.modalMsg("请选择要删除的数据", "warning");
        return;
    }
    $.modalConfirm("确认要删除选中的" + rows.length + "条数据吗?", function () {
        _ajax(prefix + '/batchRemove', {"ids": rows}, "post");
    });
}
